/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { gcoord } from './gcoord.js'

const forNumber2 = 10000;
//从WGS-84坐标系转换为BD-09坐标系
function transform_test_01() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.403988, 39.914266],
            gcoord.WGS84,
            gcoord.BD09
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09): ${endTime - startTime} ms`)
    if (result[0] != 116.41661560068297 && result[1] != 92196580126834) throw Error(`transform_test != (result[0] != 116.41661560068297 && result[1] != 92196580126834)`);

}
//// 转换GeoJSON坐标
function transform_test_02() {
    var geojson = {
        "type": "Point",
        "coordinates": [123, 45]
    }
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(geojson, gcoord.GCJ02, gcoord.WGS84);
    }
    let endTime = Date.now();
    print(`gcoord_transform(GeoJSON): ${endTime - startTime} ms`)
    if (result.coordinates[0] != 96.89033678233754 && result.coordinates[1] != 37.13318978576056) throw Error(`transform_test != (result.coordinates[0] != 96.89033678233754 && result.coordinates[1] != 37.13318978576056)`);
}

function transform_test_03() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.403988, 39.914266],
            gcoord.WGS84,
            gcoord.BD09LL
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09LL): ${endTime - startTime} ms`)
    if (result[0] != 116.41661560068297 && result[1] != 39.92196580126834) throw Error(`transform_test != (result.coordinates[0] != 116.41661560068297 && result.coordinates[1] != 39.92196580126834)`);
}
function transform_test_04() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.BD09MC,
            gcoord.WGS84
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(WGS84): ${endTime - startTime} ms`)
    if (result[0] != -0.005458395917331822 && result[1] != -0.0056431959172034245) throw Error(`transform_test != (result[0] != -0.005458395917331822 && result[1] != -0.0056431959172034245)`);
}
function transform_test_05() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [106.554231, 29.556231],
            gcoord.BD09MC,
            gcoord.BD09
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09MCtoBD09): ${endTime - startTime} ms`)
    if (result[0] != 0.0009571854186353212 && result[1] != 0.0002672839511412907) throw Error(`transform_test != (result.coordinates[0] != 0.0009571854186353212 && result.coordinates[1] != 0.0002672839511412907)`);
}
function transform_test_06() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WebMercator,
            gcoord.EPSG4326
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(EPSG4326): ${endTime - startTime} ms`)
    if (result[0] != 0.0010456749233264879 && result[1] != 0.0003585625456513216) throw Error(`transform_test != (result[0] != 0.0010456749233264879 && result[1] != 0.0003585625456513216)`);
}
function transform_test_07() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.Baidu,
            gcoord.EPSG3857
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(EPSG3857): ${endTime - startTime} ms`)
    if (result[0] != 12956629.833090782 && result[1] != 4852474.03062644) throw Error(`transform_test != (result[0] != 12956629.833090782 && result[1] != 4852474.03062644)`);
}
function transform_test_08() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS84,
            gcoord.BD09Meter
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09Meter): ${endTime - startTime} ms`)
    if (result[0] != 12959580.673891693 && result[1] != 4827036.86707346) throw Error(`transform_test != (result[0] != 12959580.673891693 && result[1] != 4827036.86707346)`);
}
function transform_test_09() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS84,
            gcoord.Baidu
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(Baidu): ${endTime - startTime} ms`)
    if (result[0] != 116.41662724378733 && result[1] != 39.922699552216216) throw Error(`transform_test != (result[0] != 116.41662724378733 && result[1] != 39.922699552216216)`);
}
function transform_test_10() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WebMercator,
            gcoord.BMap
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BMap): ${endTime - startTime} ms`)
    if (result[0] != 0.0075460290125706556 && result[1] != 0.006358687464875388) throw Error(`transform_test != (result[0] != 0.0075460290125706556 && result[1] != 0.006358687464875388)`);
}
function transform_test_11() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS84,
            gcoord.AMap
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(AMap): ${endTime - startTime} ms`)
    if (result[0] != 116.41024449916938 && result[1] != 39.91640428150164) throw Error(`transform_test != (result[0] != 116.41024449916938 && result[1] != 39.91640428150164)`);
}
function transform_test_12() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS84,
            gcoord.EPSG900913
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(EPSG900913): ${endTime - startTime} ms`)
    if (result[0] != 12958034.006300215 && result[1] != 4853597.9882998355) throw Error(`transform_test != (result[0] != 12958034.006300215 && result[1] != 4853597.9882998355)`);
}
function transform_test_13() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < 100000; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS84,
            gcoord.WGS1984
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(WGS1984): ${endTime - startTime} ms`)
    if (result[0] != 116.404 && result[1] != 39.915) throw Error(`transform_test != (result[0] != 116.404 && result[1] != 39.915)`);
}
function transform_test_14() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS1984,
            gcoord.GCJ02
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(GCJ02): ${endTime - startTime} ms`)
    if (result[0] != 116.41024449916938 && result[1] != 39.91640428150164) throw Error(`transform_test != (result[0] != 116.41024449916938 && result[1] != 39.91640428150164) `);
}
function transform_test_15() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.BD09LL,
            gcoord.GCJ02
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09LLToGCJ02): ${endTime - startTime} ms`)
    if (result[0] != 116.39762729119315 && result[1] != 39.90865673957631) throw Error(`transform_test != (result[0] != 116.39762729119315 && result[1] != 39.90865673957631) `);
}
function transform_test_16() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.WGS1984,
            gcoord.GCJ02
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(WGS1984ToGCJ02): ${endTime - startTime} ms`)
    if (result[0] != 116.41024449916938 && result[1] != 39.91640428150164) throw Error(`transform_test != (result[0] != 116.41024449916938 && result[1] != 39.91640428150164) `);
}
function transform_test_17() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.BD09Meter,
            gcoord.GCJ02
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09MeterToGCJ02): ${endTime - startTime} ms`)
    if (result[0] != -0.005458395917331822 && result[1] != -0.0056431959172034245) throw Error(`transform_test != (result[0] != -0.005458395917331822 && result[1] != -0.0056431959172034245) `);
}
function transform_test_18() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.BD09Meter,
            gcoord.EPSG3857
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(BD09MeterToEPSG3857): ${endTime - startTime} ms`)
    if (result[0] != -607.6258540654619 && result[1] != -628.1976969657687) throw Error(`transform_test != (result[0] != -607.6258540654619 && result[1] != -628.1976969657687)`);
}
function transform_test_19() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.EPSG900913,
            gcoord.GCJ02
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(EPSG900913ToGCJ02): ${endTime - startTime} ms`)
    if (result[0] != 0.0010456749233264879 && result[1] != 0.0003585625456513216) throw Error(`transform_test != (result[0] != 0.0010456749233264879 && result[1] != 0.0003585625456513216)`);
}
function transform_test_20() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.GCJ02,
            gcoord.BD09LL
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(GCJ02ToBD09LL): ${endTime - startTime} ms`)
    if (result[0] != 116.41036949371029 && result[1] != 39.92133699351021) throw Error(`transform_test != (result[0] != 116.41036949371029 && result[1] != 39.92133699351021) `);
}
function transform_test_21() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.GCJ02,
            gcoord.WGS1984
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(GCJ02ToWGS1984): ${endTime - startTime} ms`)
    if (result[0] != 116.39775550083061 && result[1] != 39.91359571849836) throw Error(`transform_test != (result[0] != 116.39775550083061 && result[1] != 39.91359571849836)`);
}
function transform_test_22() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.GCJ02,
            gcoord.BD09Meter
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(GCJ02ToBD09Meter): ${endTime - startTime} ms`)
    if (result[0] != 12958884.056760045 && result[1] != 4826839.876883989) throw Error(`transform_test != (result[0] != 12958884.056760045 && result[1] != 4826839.876883989)`);
}
function transform_test_23() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.EPSG3857,
            gcoord.BD09Meter
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(EPSG3857ToBD09Meter): ${endTime - startTime} ms`)
    if (result[0] != 840.028925707585 && result[1] != 703.0659645371794) throw Error(`transform_test != (result[0] != 840.028925707585 && result[1] != 703.0659645371794)`);
}
function transform_test_24() {
    let result;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = gcoord.transform(
            [116.404, 39.915],
            gcoord.GCJ02,
            gcoord.EPSG900913
        );
    }
    let endTime = Date.now();
    print(`gcoord_transform(GCJ02ToEPSG900913): ${endTime - startTime} ms`)
    if (result[0] != 12957338.871832423 && result[1] != 4853394.177516373) throw Error(`transform_test != (result[0] != 12957338.871832423 && result[1] != 4853394.177516373)`);
}
transform_test_01()
transform_test_02()
transform_test_03()
transform_test_04()
transform_test_05()
transform_test_06()
transform_test_07()
transform_test_08()
transform_test_09()
transform_test_10()
transform_test_11()
transform_test_12()
transform_test_13()
transform_test_14()
transform_test_15()
transform_test_16()
transform_test_17()
transform_test_18()
transform_test_19()
transform_test_20()
transform_test_21()
transform_test_22()
transform_test_23()
transform_test_24()